#### BEGIN project specific configuration
# library, projecte name and version number:
lib_name= opencv-examples
project_name = pure-$(lib_name)
version = 0.1

#entries below can be blank - set as apropriate
#generated pure files * will be deleted by clean *
GENPUREFILES =
#manually created pure files * will not be deleted by clean *
MANPUREFILES = flip_image.pure morph_bench.pure
#pure code (will be installed)
PUREFILES = $(MANPUREFILES) $(GENPUREFILES)
#generated c files * will be deleted by clean *
GENCFILES =
#manually created cfiles * will not be delete by clean *
MANCFILES = morph_bench.c
#all c files
CFILES = $(GENCFILES) $(MANCFILES)
#all source include source used only during build
SOURCEFILES = $(PUREFILES) $(CFILES) 
#all files to be included in a source release
DISTFILES =
dist = $(project_name)-$(version)
target = $(project_name)

# Default CFLAGS are -g -O2, CPPFLAGS, LDFLAGS and LIBS are empty by default.
# These can be set from the command line as usual. Use CFLAGS, CPPFLAGS and
# LDFLAGS for compiler (-O etc.), preprocessor (-I etc.) and linker (-L etc.) 
# options, respectively. LIBS is to be used for additional libraries to be
# linked (-l etc.).
INCLUDE_PATH = /usr/include
CFLAGS = -g -O2 -fopenmp

## MSYS silently converts drive paths (like /c/..) to c:/,
## so we have to give that way to assure matching with the -s glob-pattern of pure-gen
opencvdir = c:/Opt/OpenCV2.0
opencvbuilddir = $(opencvdir)/build
opencvver = 200
opencvincdir = $(opencvdir)/include
opencvlibdir = $(opencvbuilddir)/lib

CPPFLAGS = -I$(opencvincdir)
LDFLAGS = -L$(opencvlibdir)
LIBS = -lcv$(opencvver) -lcxcore$(opencvver) -lhighgui$(opencvver)

puredir = c:/Opt/Pure
purelibdir = $(puredir)/lib
#PUREFLAGS = -v64 -I..
PUREFLAGS = -v64 -I.. -L$(puredir) -L$(purelibdir)

# project specific build tasks should be located after all task below

#### END project specific configuration
#### standard targes , probable don't need to edit below here

# Try to guess the host system type.
host = $(shell ./config.guess)

# Try to guess the installation prefix (this needs GNU make):
prefix = $(patsubst %/bin/pure,%,$(shell which pure 2>/dev/null))

ifeq ($(strip $(prefix)),)
ifneq "$(findstring -mingw,$(host))" ""
# Windows
prefix = $(patsubst %/pure,%,$(shell which pure 2>/dev/null))
else
# Fall back to /usr/local.
prefix = /usr/local
endif
endif

# Installation goes into $(libdir)/pure, you can also set this directly
# instead of $(prefix).
libdir = $(prefix)/lib

# Platform-specific defaults, edit this as needed.
#PIC = -fPIC # uncomment for x86-64 compilation
DLL = .so
EXE =
shared = -shared

# Take care of some common systems.
ifneq "$(findstring -mingw,$(host))" ""
# Windows
DLL = .dll
EXE = .exe
endif
ifneq "$(findstring -darwin,$(host))" ""
# OSX (untested)
DLL = .dylib
EXE =
shared = -dynamiclib
endif
ifneq "$(findstring x86_64-,$(host))" ""
# 64 bit, needs -fPIC flag
PIC = -fPIC
endif
FLAGS = $(CPPFLAGS) $(CFLAGS) $(PIC) $(LDFLAGS)

# PGFLAGS for pure-gen
PGFLAGS = -v

all : $(basename $(CFILES))_c$(EXE) $(basename $(PUREFILES))$(EXE)

#### BEGIN project specific build tasks

$(basename $(CFILES))_c$(EXE): $(CFILES)
	gcc $(FLAGS) -o $@ $< $(LIBS)

$(basename $(PUREFILES))$(EXE): $(PUREFILES)
	pure $(PUREFLAGS) -c -s -o $@ $(basename $@).pure
	
#### END   project specific build tasks


clean: 
	rm -f *$(EXE) $(GENCFILES) $(GENPUREFILES) *.aux *.log *.out \
              doc/*.pdf doc/*.tex doc/*.html doc/*.txt $(dist).tar.gz *~
	rm -rf $(dist)
	
# documentation (this needs docutils)

doc/$(target).txt: $(SOURCEFILES)
	pure-doc $< > $@

.PHONY: html tex pdf

html: doc/$(target).html
tex: doc/$(target).tex
pdf: doc/$(target).pdf

doc/%.html: doc/%.txt
	rst2html.py $< $@
doc/%.tex: doc/%.txt
	rst2latex.py $< $@

# This also requires that you have TeX installed.

doc/%.pdf: doc/%.tex
	pdflatex $<
	pdflatex $<
	rm -f *.aux *.log *.out
	mv ../$@ doc

install:
	test -d "$(DESTDIR)$(libdir)/pure" || mkdir -p "$(DESTDIR)$(libdir)/pure"
	cp $(PUREFILES) $(lib_name)$(DLL) doc/$(project_name).html "$(DESTDIR)$(libdir)/pure"

uninstall:
	rm -f "$(DESTDIR)$(libdir)/pure/$(PUREFILES)" "$(DESTDIR)$(libdir)/pure/$(lib_name)$(DLL)" "$(DESTDIR)$(libdir)/pure/$(project_name).html"
	for f in $(PUREFILES); do rm -f "$(DESTDIR)$(libdir)/pure/$$f"; done

dist: doc/$(target).html
	rm -rf $(dist)
	mkdir $(dist) && mkdir $(dist)/examples && mkdir $(dist)/doc
	for x in $(DISTFILES); do ln -sf $$PWD/$$x $(dist)/$$x; done
	rm -f $(dist).tar.gz
	tar cfzh $(dist).tar.gz $(dist)
	rm -rf $(dist)
